<template>
  <div id="apptb">
    <div class="grouptitle">
      <div class="grouptitletext">人员信息管理</div>
    </div>

    <div class="contentall">
      <div class="contentallcontent">
        <div class="contentss">
          <!-- 每一行 -->
          <div class="inputall">
            <div class="inputleft">
              <label for="">人员身份</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.statusname"
              >
                <option value="领队">领队</option>
                <option value="教练">教练</option>
                <option value="裁判">裁判</option>
                <option value="运动员">运动员</option>
                <option value="陪练人员">陪练人员</option>
                <option value="随队人员或队医">随队人员或队医</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">兼职情况</label>
              <!-- <input type="text" class="inputtextte" v-model="staffInfo.job" /> -->
              <input
                type="radio"
                value="兼教练"
                v-model="staffInfo.job"
                @change="getjob"
                name="habit"
              />
              <label>兼教练</label>

              <input
                type="radio"
                value="兼运动员"
                v-model="staffInfo.job"
                @change="getjob"
                name="habit"
              />
              <label>兼运动员</label>
            </div>
          </div>
          <!--  -->
          <div class="inputall">
            <div class="inputleft">
              <label for="">身份证号</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.idcard"
              />
            </div>
            <div class="inputright">
              <label for="">姓名</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.username"
              />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">性别</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.sex"
              >
                <option value="男">男</option>
                <option value="女">女</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">出生日期</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.birthday"
              />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">手机号码</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.phone"
              />
            </div>
            <div class="inputright">
              <label for="">E-Mall</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.email"
              />
            </div>
          </div>
          <!-- vipdata -->
          <div class="inputall">
            <div class="inputleft">
              <label for=""></label>
              <input type="checkbox" class="inputtextte" v-model="isVip" />
            </div>
            <div class="inputright">
              <label for="">会员有效期</label>
              <input
                v-show="isVip"
                type="date"
                class="inputtextte"
                v-model="staffInfo.vipdata"
              />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">现有段位</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.danxz"
              >
                <option value="无">无</option>
                <option value="青铜">青铜</option>
                <option value="黄金">黄金</option>
                <option value="铂金">铂金</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">段位证号</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.iddan"
              />
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">服务选择</label>
            </div>
            <div
              class="inputright"
              v-for="(item, index) in checkList"
              :key="index"
            >
              <input
                type="radio"
                name="service"
                v-model="staffInfo.service"
                @change="getservice"
                :value="item.name"
              />
              <label for="" style="width: 100px">{{ item.name }}</label>
            </div>
          </div>
          <div class="inputall">
            <div class="inputleft">
              <label for="">报考段位</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.danbk"
              >
                <option value="无">无</option>
                <option value="青铜">青铜</option>
                <option value="黄金">黄金</option>
                <option value="铂金">铂金</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">所属协会</label>
              <input
                type="text"
                class="inputtextte"
                v-model="staffInfo.association"
              />
            </div>
          </div>

          <div class="inputall">
            <div class="inputleft">
              <label for="">加注信息</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.jiazhu"
              >
                <option value="正常日程">正常日程</option>
                <option value="不正常日程">不正常日程</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">旅游信息</label>

              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.tour"
              >
                <option value="参加">参加</option>
                <option value="不参加">不参加</option>
              </select>
            </div>
          </div>

          <div class="inputall">
            <div class="inputleft">
              <label for="">纪念品信息</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.souvenir"
              >
                <option value="纪念衫xxs">纪念衫xxs</option>
                <option value="纪念衫xs">纪念衫xs</option>
                <option value="纪念衫M">纪念衫M</option>
                <option value="纪念衫L">纪念衫L</option>
                <option value="纪念衫xL">纪念衫xL</option>
              </select>
            </div>
            <div class="inputright">
              <label for="">户籍所在</label>
              <select
                id="continent"
                class="inputtextte"
                v-model="staffInfo.censusr"
              >
                <option value="中国大陆居民">中国大陆居民</option>
              </select>
            </div>
          </div>

          <div class="inputall">
            <div class="inputleft">
              <label for="">照片</label>
              <input
                type="text"
                class="inputtextte"
                id="xqdzipt"
                style="width: 208px"
                v-model="staffInfo.img"
              />
            </div>
          </div>

          <!-- bottom -->
          <div class="inputall">
            <div class="bottomimg" @click="submitshut">
              <img :src="'http://localhost:3002/upload/add.png'" alt="" />
              <span>保存并关闭本窗</span>
            </div>
            <div class="bottomimg" style="margin-left: 15px" @click="submitgo">
              <img :src="'http://localhost:3002/upload/add.png'" alt="" />
              <span>保存并继续报名</span>
            </div>
          </div>
        </div>

        <div class="bottombox"></div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  data: function () {
    return {
      checkList: [
        { id: 1, name: "综合服务" },
        { id: 2, name: "参加晚宴" },
        { id: 3, name: "未成年人拼床" },
        { id: 4, name: "单人间" },
      ],
      isVip: false,

      staffInfo: {
        statusname: "",
        job: "",
        idcard: "",
        username: "",
        sex: "",
        birthday: "",
        phone: "",
        email: "",
        vipdata: "无",
        danxz: "无",
        iddan: "无",
        service: "",
        danbk: "无",
        association: "",
        jiazhu: "正常日程",
        tour: "",
        souvenir: "",
        censusr: "",
        img: "未上传",
      },
      errorMessages: [], // 用于收集错误消息的数组
      isupdateAdd: false,
      updateId: 0,
    };
  },

  methods: {
    // 保存并关闭：
    submitshut() {
      // ：是否是非空字符串
      function isNonEmptyStringIfString(value) {
        return (
          typeof value !== "string" ||
          (typeof value === "string" && value.trim() !== "")
        );
      }
      if (Object.values(this.staffInfo).every(isNonEmptyStringIfString)) {
        if (this.isupdateAdd) {
          this.updategetbyid(this.updateId);
          this.$message({
            message: "修改成功",
            type: "success",
          });
        } else {
          this.addstaff();
          this.$message({
            message: "添加成功",
            type: "success",
          });
        }
        // 如果需要关闭窗口，取消注释下面的代码
        // window.close(); // 关闭窗口
      } else {
        this.$message("请填写完整信息");
      }
    },

    // 保存并继续：
    submitgo() {},

    // 新增 人员：
    addstaff() {
      axios({
        method: "post",
        url: "http://localhost:3002/competition/staff/add",
        data: this.staffInfo,
      }).then((res) => {
        // console.log(res.data);
      });
    },

    // 修改 人员
    updategetbyid(id) {
      axios({
        method: "post",
        url: "http://localhost:3002/competition/staff/update",
        data: {
          id: id,
          statusname: this.staffInfo.statusname,
          job: this.staffInfo.job,
          idcard: this.staffInfo.idcard,
          username: this.staffInfo.username,
          sex: this.staffInfo.sex,
          birthday: this.staffInfo.birthday,
          phone: this.staffInfo.phone,
          email: this.staffInfo.email,
          vipdata: this.staffInfo.vipdata,
          danxz: this.staffInfo.danxz,
          iddan: this.staffInfo.iddan,
          service: this.staffInfo.service,
          danbk: this.staffInfo.danbk,
          association: this.staffInfo.association,
          jiazhu: this.staffInfo.jiazhu,
          tour: this.staffInfo.tour,
          souvenir: this.staffInfo.souvenir,
          censusr: this.staffInfo.censusr,
          img: this.staffInfo.img,
        },
      }).then((res) => {
        console.log(res.data);
      });
    },

    // 获取 单个人员信息
    getstaffone() {
      axios({
        url: "http://localhost:3002/competition/staff/getbyId",
        method: "post",
        data: { id: this.updateId },
      }).then((res) => {
        // console.log(res.data.list[0]);
        this.staffInfo = res.data.list[0];
      });
    },

    getservice() {
      console.log(this.staffInfo.service);
    },

    getjob(e) {
      console.log(e);
      console.log(this.staffInfo.job);
    },
    submitall() {},
  },

  mounted() {
    // 获取 修改 按钮 传递 过来的id：
    var url = window.location.href;
    var params = new URLSearchParams(url.split("?")[1]);
    var id = params.get("id");
    this.updateId = id;
    // console.log(this.updateId); // 打印出 id 参数的值
    if (id) {
      this.getstaffone();
      this.isupdateAdd = true;
    }
  },
};
</script>

<style lang="less" scoped>
#apptb {
  //   transform: scale(0.9);

  margin: auto;
  margin-top: 40px;
  background-color: #fff;
  width: 60%;
  height: 85%;
  .grouptitle {
    width: 100%;
    height: 45px;
    background: linear-gradient(#9bcdee, #6190b5);
    color: #fff;
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
  }
  .contentall {
    background-color: #74b0e7;
    width: 100%;
    height: 92%;
    padding-top: 6px;
    .contentallcontent {
      width: 98.5%;
      height: 99%;
      background-color: #d5e8fb;
      margin: 0 6px;
      border-radius: 10px;
      position: relative;
      .contentss {
        width: 98%;
        // height: 80%;
        margin: 0 10px;
        background-color: #eef7ff;
        transform: translateY(3%);
        border: 1px solid rgb(206, 200, 200);
        // 每一行
        .inputall {
          background-color: #eef7ff;
          margin: 0px 6px;
          height: 40px;
          font-size: 15px;
          border-bottom: 1px solid rgb(206, 200, 200);
          display: flex;
          align-items: center; /* 垂直居中 */
          select {
            height: 25px;
            width: 227px !important;
          }
          .bottomimg {
            display: flex;
            align-items: center; /* 垂直居中 */
            transform: translateX(220%);
            background: linear-gradient(#f6f6f6, #e1e1e1);
            padding: 4px 10px;
            border-radius: 5px;
            border: 1px solid rgb(174, 171, 171);
            img {
              width: 20px;
              height: 20px;
              margin-right: 8px;
            }
          }

          .inputleft {
            display: inline-block;
            vertical-align: top;
            padding: 0 6px;
            .xqdzipt {
              display: inline-block;
              width: 400px !important;
            }
            label {
              //   padding-right: 5px;
              display: inline-block;
              //   background-color: red;
              width: 80px;
              text-align: center;
            }
            .inputtextte {
              width: 220px;
            }
          }
          .inputright {
            display: inline-block;
            vertical-align: top;
            margin-left: 5px;
            label {
              //   padding-right: 5px;
              display: inline-block;
              //   background-color: red;
              width: 80px;
              text-align: center;
            }
            .inputtextte {
              width: 220px;
            }
          }
        }
      }

      .bottombox {
        background-color: #eef7ff;
        width: 100%;
        height: 18px;
        // transform: translateY(230%);
        position: absolute;
        bottom: 0;
      }
    }
  }
}
</style>